package com.woyou.ui.activity;

import java.util.ArrayList;
import java.util.List;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.TextView;

import com.citaq.ideliver.R;
import com.woyou.ui.adapter.SuperViewPagerAdapter;
import com.woyou.utils.SharedpreferncesUtil;

public class WelcomeActivity extends BaseActivity {

	// 介绍页面
	private ViewPager introductVp;
	private SuperViewPagerAdapter viewPagerAdapter;
	private List<View> views = new ArrayList<View>(); // Tab页面列表
	private ImageView layout_introduct_iv1;
	private ImageView layout_introduct_iv2;
	private ImageView layout_introduct_iv3;
	private TextView start;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.layout_welcome);
		initView();
	}

	@SuppressWarnings("deprecation")
	private void initView() {

		introductVp = (ViewPager) findViewById(R.id.viewpager);
		// layout_introduct_iv1 = (ImageView) findViewById(R.id.layout_introduct_iv1);
		// layout_introduct_iv2 = (ImageView) findViewById(R.id.layout_introduct_iv2);
		// layout_introduct_iv3 = (ImageView) findViewById(R.id.layout_introduct_iv3);
		// introductVp.setOffscreenPageLimit(3);

		// View view1 = View.inflate(mContext, R.layout.item_introduct_v1, null);
		// View view2 = View.inflate(mContext, R.layout.item_introduct_v2, null);
		View view3 = View.inflate(mContext, R.layout.item_introduct_v3, null);

		// 监听登录立即体验按钮
		start = (TextView) view3.findViewById(R.id.item_introduct_finish);
		start.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				if (SharedpreferncesUtil.getGuided(mContext)) {
					finish();
				} else {
					SharedpreferncesUtil.setGuided(mContext);
					Intent intent = new Intent(WelcomeActivity.this, HomeActivity_.class);
					startActivity(intent);
					finish();
				}
				
				
			}
		});

		// views.add(view1);
		// views.add(view2);
		views.add(view3);
		viewPagerAdapter = new SuperViewPagerAdapter(views);
		introductVp.setAdapter(viewPagerAdapter);
		introductVp.setOnPageChangeListener(new OnPageChangeListener() {
			@Override
			public void onPageSelected(int arg0) {
				// setItemFocus(arg0);
			}

			@Override
			public void onPageScrolled(int arg0, float arg1, int arg2) {
				// TODO Auto-generated method stub
			}

			@Override
			public void onPageScrollStateChanged(int arg0) {
				// TODO Auto-generated method stub
			}
		});
	}
	
	/**
	 * 根据传入参数设置焦点
	 * 
	 * @param index
	 */
	public void setItemFocus(int index) {
		layout_introduct_iv1.setImageResource(R.raw.icon_introduct_focus);
		layout_introduct_iv2.setImageResource(R.raw.icon_introduct_focus);
		layout_introduct_iv3.setImageResource(R.raw.icon_introduct_focus);
		layout_introduct_iv1.setVisibility(View.VISIBLE);
		layout_introduct_iv2.setVisibility(View.VISIBLE);
		layout_introduct_iv3.setVisibility(View.VISIBLE);
		switch (index) {
		case 0:
			layout_introduct_iv1.setImageResource(R.raw.icon_introduct_unfocus);
			break;
		case 1:
			layout_introduct_iv2.setImageResource(R.raw.icon_introduct_unfocus);
			break;
		case 2:
			layout_introduct_iv1.setVisibility(View.GONE);
			layout_introduct_iv2.setVisibility(View.GONE);
			layout_introduct_iv3.setVisibility(View.GONE);
			break;
		}
	}


	@Override
	public boolean backOperate() {
		// TODO Auto-generated method stub
		return false;
	}

}
